package 
{
    import flash.events.*;
    import flash.display.*;
    import flash.media.*;
    import flash.net.*;
	import flash.geom.*;
	
	// Load the TweenMax Class Libraries
	import gs.*; 
	import gs.easing.*;

    public class Ball extends MovieClip {
		
		private var ballXTarget:Number = 300;
		private var ballYTarget:Number = 300;
		private var myStage:Object;

        public function Ball(_stage:Object) {
	
			this.cacheAsBitmap = true;
			myStage = _stage;
			
			// Set a nice random size for the ball
			this.width = this.height = Math.random() * 200;
			
			// Start the ball moving
			ballGo();
        }

		private function ballGo ():void
		{
			TweenMax.to(this, 0.25, {x:ballXTarget, y:ballYTarget, ease:Expo.easeInOut, onComplete:updateBallTargets});
		}
		
		private function updateBallTargets ():void
		{
			ballXTarget = Math.random() * myStage.stageWidth;
			ballYTarget = Math.random() * myStage.stageHeight;
			
			ballGo();
		}
    }
}
